New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update: Fix call, new and member expressions in no-extra-parens #12302
Conversation
I'm a bit confused. Parents are needed for the first expression: |
The
Yes, valid. Constructors can return another constructor. function Foo() {
return Bar
}
function Bar() {
}
var bar = new new Foo // a Bar's instance.
I agree. But the problem is |
It's the same thing, but the extra parens could be indeed helpful in this situation to avoid confusion. That's why I was wondering was it intentionally omitted. However, there is no test case to show this intention, so I believe it's a bug (unintentional oversight). |
Ah, I did mix it up with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
What is the purpose of this pull request? (put an "X" next to item)
[X] Bug fix
This PR fixes 3 things in
no-extra-parens
:object
node in aMemberExpression
is aNewExpression
with parens. Example:(new foo()).bar
. This change can generate more warnings by default.NewExpression
is thecalee
of aCallExpression
or aNewExpression
. Example:(new new foo())()
leftParenToken.loc
instead of justleftParenToken.loc.start
.Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue.
Demo link
What did you expect to happen?
1 error, for the first line only.
What actually happened? Please include the actual, raw output from ESLint.
2 errors and invalid autofix for the other two lines.
What changes did you make? (Give an overview)
MemberExpression
.isNewExpressionWithParens
function.loc
instead ofloc.start
.Is there anything you'd like reviewers to focus on?
Please verify that these are indeed false positives/negatives, and that the false negative wasn't intentional (I guess it's a bug as there were no test cases to confirm that it was intentional).